package com.onlyxiahui.common.action.description.util;

import java.math.BigInteger;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Description <br>
 * Date 2020-01-08 16:37:53<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class ActionClassUtil {

	public static boolean isBean(Class<?> classType) {
		if (null != classType) {
			boolean isBean = !classType.isAnnotation() &&
					!classType.isArray() &&
					!classType.isEnum() &&
					!classType.isInterface() &&
					!classType.isPrimitive() &&
					!isPrimitive(classType) &&
					!isBaseProperty(classType);

			return isBean;
		}
		return false;
	}

	public static boolean isPrimitive(Class<?> classType) {
		return null != classType && ((classType.isPrimitive()) ||
				(classType == Integer.class) || (classType == int.class) ||
				(classType == Long.class) || (classType == long.class) ||
				(classType == Float.class) || (classType == float.class) ||
				(classType == Double.class) || (classType == double.class) ||
				(classType == Byte.class) || (classType == byte.class) ||
				(classType == Character.class) || (classType == char.class) ||
				(classType == Boolean.class) || (classType == boolean.class) ||
				(classType == Short.class) || (classType == short.class));
	}

	public static boolean isBaseProperty(Class<?> classType) {
		return Comparable.class.isAssignableFrom(classType);
	}

	public static boolean isArray(Class<?> classType) {
		return classType.isArray();
	}

	public static boolean isString(Class<?> classType) {
		return CharSequence.class.isAssignableFrom(classType);
	}

	public static boolean isBoolean(Class<?> classType) {
		return Boolean.class == classType || boolean.class == classType || Boolean.class.isAssignableFrom(classType);
	}

	public static boolean isInteger(Class<?> classType) {
		return BigInteger.class.isAssignableFrom(classType) ||
				Integer.class.isAssignableFrom(classType) || int.class.isAssignableFrom(classType) ||
				Long.class.isAssignableFrom(classType) || long.class.isAssignableFrom(classType);
	}

	public static boolean isNumber(Class<?> classType) {
		return Number.class.isAssignableFrom(classType);
	}

	public static boolean isCollection(Class<?> classType) {
		return Collection.class.isAssignableFrom(classType);
	}

	public static boolean isMap(Class<?> classType) {
		return Map.class.isAssignableFrom(classType);
	}

	public static boolean isBaseEntityMap(Class<?> classType) {
		return null != classType && Map.class.isAssignableFrom(classType) && (classType == SortedMap.class ||
				classType == TreeMap.class ||
				classType == LinkedHashMap.class ||
				classType == HashMap.class ||
				classType == ConcurrentHashMap.class ||
				classType == Properties.class ||
				classType == Hashtable.class);
	}
}
